<script>
<!--
var sort_by = '';
var sort_order = 0;
var current_view = '';
var page = 1;

function listReload(page)
{
    $('#indexAjax').html('<div align="center"><div class="loader_admin"></div></div>');
    $('#indexAjax').load('<?php echo url_for('@ground_order_list') ?>?'+$('#filterSearch').serialize(), {
        sort_by:      sort_by,
        sort_order:   sort_order,
        page:         page,
        view:         current_view,
    });
}

function sort(type, default_order) {
    if (type != sort_by) {
        sort_by = type;
        sort_order = default_order;
    } else if(sort_order) {
        sort_order = 0
    } else {
        sort_order = 1;
    }
    listReload(1);
}

function loadSchedule() {
	ground_id = $('#ground_order_ground_id').val();
	$('#ground_order_schedule').load('<?php echo url_for('@ground_order_load_schedule') ?>'+'?type=schedule&'+$('#filterSearch').serialize(),{
		ground_id: ground_id
	});
}

function loadCost() {
	ground_id = $('#ground_order_ground_id').val();
	schedule = $('#ground_order_schedule').val();
	$.ajax({
	  type: "POST",
	  url: '<?php echo url_for('@ground_order_load_schedule') ?>'+'?type=cost',
	  data: { ground_id: ground_id, schedule: schedule },
	  success: function(data) {
	   $('#cost').val(data);
	  }
	});
}
$(function() {
		$( "#ground_order_reserved_date" ).datepicker({
			showOn: "button",
			minDate: new Date(),
		});
	});
function form_valide()
{
	ok = true;
	message = '';
	customer_id = $('#ground_order_customer_id').val();
	if (customer_id == '') {
		ok = false;
		message += "Tên khách hàng là bắt buộc\n";
	}
	reserved_date = $('#ground_order_reserved_date').val();
	if (reserved_date == '') {
		ok = false;
		message += "Ngày đặt sân là bắt buộc\n";
	}
	ground_id = $('#ground_order_ground_id').val();
	if (ground_id == '') {
		ok = false;
		message += "Tên sân là bắt buộc\n";
	}
	schedule = $('#ground_order_schedule').val();
	if (schedule == '') {
		ok = false;
		message += "Giờ đặt sân là bắt buộc\n";
	}
	if (!ok)
		alert("Có lỗi khi đặt sân :\n"+message);
	return ok;
}
-->
</script>
<h1>Đặt Sân</h1>
<div id="SearchForm" class='backend_form'>
  <form id="filterSearch" action="<?php echo url_for('@ground_order_list') ?>" method="post">
    <table>
      <?php echo $order_form ?>
      <tr>
      	<th>Dịch vụ thêm</th>
        <td>
        	<?php
				foreach ($facilities as $facility)
				{
			?>
				<div style='display:block;padding:5px 0;'>
					<div style='float:left'>
						<input type='checkbox' name='ground_order_facility_<?php echo $facility['id'] ?>' id='ground_order_facility_<?php echo $facility['id'] ?>' /> 
					</div>
					<div style='float:left; padding-top:3px; padding-left:3px; '>
						<label for="ground_order_facility_<?php echo $facility['id'] ?>">
							<?php echo $facility['name'] ?> - <span style="color:#c00;"><?php echo $facility['value'] ?> VNĐ</span>
						</label>
					</div>
					<div style='clear:both'></div>
				</div>
			<?
				}
			?>
        </td>
      </tr>     
	  <tr>
		<th><lable for="cost">Giá sân</label></th>
		<td><input type="text" id="cost" name="cost"></td>
	  </tr>
      <tr><th>
        <input  id="fs" type="submit" value="<?php echo "Search" ?>"/>
		<input id="create" type="submit" name="create" value="Create" onclick="return form_valide();" />
		<?php if (isset($create_success) && $create_success): ?>
			<div><span>Đặt sân thành công</span></div>
		<?php endif ?>
      </th></tr>
    </table>
  </form>
</div>
      
<div style='padding-top:10px;'>
<div class="UITable">
  <div id="indexAjax" class='filter_form'>
    <?php include 'listAjax.php' ?>
  </div>
</div>
</div>